package com.example.demo.utils;



import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 知识图谱后端文件处理工具类
 * COS配置类
 * @author wzh
 * @date 2025.4.16
 */


@Component
@ConfigurationProperties(prefix = "conf.cos")
@Data
public class CosConfigProperties {
    /**
     * 账号ID
     */
    @Value("${cos.conf.secretId}")
    private String secretId;
    /**
     * 秘钥
     */
    @Value("${cos.conf.secretKey}")
    private String secretKey;
    /**
     * 地区
     */
    @Value("${cos.conf.region}")
    private String region;
    /**
     * 桶名称
     */
    @Value("${cos.conf.bucket-name}")
    private String bucketName;
    /**
     * 路径
     */
    @Value("${cos.conf.path}")
    private String path;
    /**
     * 文件夹路径
     */
    @Value("${cos.conf.folder}")
    private String folder;

    /**
     * 统一获取cos客户端
     */
    @Bean
    public COSClient cosClient(){
        //认证身份信息
        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
        //区域
        Region region = new Region(this.region);
        //客户端配置
        ClientConfig clientConfig = new ClientConfig(region);
        //new一个客户端
        COSClient cosClient = new COSClient(cred, clientConfig);
        return cosClient;
    }

    public String getSecretId() {
        return secretId;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public String getRegion() {
        return region;
    }

    public String getBucketName() {
        return bucketName;
    }

    public String getPath() {
        return path;
    }

    public String getFolder() {
        return folder;
    }
}